package com.example.uiwidgettest

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View.*
import androidx.appcompat.app.AlertDialog
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    private var images = intArrayOf(R.drawable.hqsw,R.drawable.welt,R.drawable.xnylh)
    private var curimg = 0


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        btnShowEdit.setOnClickListener {
            textView1.text = editText1.text
        }

        button2.setOnClickListener {
            progress1.apply {
                visibility = when(visibility){
                VISIBLE -> GONE
                GONE -> VISIBLE
                else -> GONE
            } }
        }
        button1.setOnClickListener {
            progressBar1.progress += 10
        }

        image1.setImageResource(images[curimg])
        btnChangeImg.setOnClickListener {
            image1.setImageResource(images[++curimg % images.size])
        }

        btnDialog.setOnClickListener {
            AlertDialog.Builder(this).apply {
                title = "This is Dialog"
                setMessage("SomeThing important!")
                setCancelable(false)
                setPositiveButton("OK"){
                    dialog,which ->
                }
                setNegativeButton("Cancel"){
                        dialog,which ->
                }
                show()
            }
        }




    }
}
